<form autocomplete="off" class="layui-form layui-box modal-form-box" action="{:request()->url()}" data-auto="true" method="post">

    <div class="layui-form-item">
        <label class="layui-form-label">用户账号</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.name)}
            <input readonly="readonly" disabled="disabled" name="name" value='{$vo.name|default=""}' required="required" title="请输入用户名称" placeholder="请输入用户名称" class="layui-input layui-bg-gray">
            {else}
            <input name="name" value='{$vo.name|default=""}' required="required" pattern="^.{4,}$" title="请输入用户名称" placeholder="请输入4位及以上字符用户名称" class="layui-input">
            {/if}
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">联系手机</label>
        <div class="layui-input-block">
            <input type="tel" autofocus name="phone" readonly="readonly" value='{$vo.phone|default=""}' pattern="^1[3-9][0-9]{9}$" title="请输入联系手机" placeholder="请输入联系手机" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">联系邮箱</label>
        <div class="layui-input-block">
            <input name="mail" pattern="^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$" value='{$vo.mail|default=""}' title="请输入联系邮箱" placeholder="请输入联系邮箱" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">厂家图片</label>
        <div class="layui-input-block">
            <div class='col-sm-8'>
                <img data-tips-image class='col-sm-8' src="{$vo.shop_img|default=''}"/>
                <input type="hidden" name="shop_img"  onchange="$(this).prev('img').attr('src', this.value)"
                       value="{$vo.shop_img|default=''}" class="layui-input">
                <a class="btn btn-info" style="float: right" data-file="one" data-field="shop_img ">上传图片</a>
                <p>建议上传尺寸为500x300px</p>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">厂家名称</label>
        <div class="layui-input-block">
            <input   title="必须填写厂家名称"  required="required" name="shop_name" value='{$vo.shop_name|default=""}' placeholder="必填" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label form-require">归属区域：</label>

        <div class="layui-col-sm2 layer-midd-left">
            <select id="provinceid" name="province"  lay-verify="required" onchange="sheng()" style="display: block" class="layui-input">
                <option value="">全部</option>
                {foreach $areaList as $val}
                {if !empty($vo)}
                {if $val['id'] == $vo['province']}
                <option value="{$val['id']}" selected = "selected">{$val['area_name']}</option>
                {else/}
                <option value="{$val['id']}">{$val['area_name']}</option>
                {/if}
                {else/}
                <option value="{$val['id']}">{$val['area_name']}</option>
                {/if}
                {/foreach}

            </select>
        </div>

        <div class="layui-col-sm2 layer-midd-left">
            <select id="cityid" name="city" lay-verify="required" onchange="xian()" style="display: block" class="layui-input">
                <option value="">全部</option>
                {if !empty($areaifno)}
                {foreach $areaifno as $c}
                {if !empty($vo['province'])}
                {if $c['area_parent_id'] == $vo['province']}
                {if $c['id'] == $vo['city']}
                <option value="{$c['id']}" selected = "selected">{$c['area_name']}</option>
                {else/}
                <option value="{$c['id']}">{$c['area_name']}</option>
                {/if}
                {/if}
                {/if}
                {/foreach}
                {/if}
            </select>
        </div>

        <div class="layui-col-sm2 layer-midd-left">
            <select id="districtid" name="area" lay-verify="required" style="display: block" class="layui-input">
                <option value="">全部</option>
                {if !empty($areaifno)}
                {foreach $areaifno as $a}
                {if !empty($vo['city'])}
                {if $a['area_parent_id'] == $vo['city']}
                {if $a['id'] == $vo['area']}
                <option value="{$a['id']}" selected = "selected">{$a['area_name']}</option>
                {else/}
                <option value="{$a['id']}">{$a['area_name']}</option>
                {/if}
                {/if}
                {/if}
                {/foreach}
                {/if}
            </select>
        </div>
    </div>
    <style>
        .layui-col-sm2 .layui-unselect{ display: none;}
    </style>
    <div class="layui-form-item">
        <label class="layui-form-label">所在经度</label>
        <div class="layui-input-block">
            <input  title="必须所在经度" name="lng" value='{$vo.lng|default=""}' placeholder="必填·" required="required" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">所在纬度</label>
        <div class="layui-input-block">
            <input  title="必须所在纬度" name="lat" value='{$vo.lat|default=""}' placeholder="必填·" required="required" class="layui-input">
            <a href='https://lbs.qq.com/tool/getpoint/index.html'target="_blank" style="float: right;">前往选取位置</a>
            <div style="display:block;clear:both;"></div>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">详细位置</label>
        <div class="layui-input-block">
            <input  title="必须填写公司位置" name="address" value='{$vo.address|default=""}' placeholder="必填·" required="required" class="layui-input">
            <div style="display:block;clear:both;"></div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">标语</label>
        <div class="layui-input-block">
            <input   title="必须填写厂家标语"  required="required" name="remark" value='{$vo.remark|default=""}' placeholder="必填" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">

            <textarea name="content">{$vo.content|default=''}</textarea>
            <script>
                require(['ckeditor'], function () {
                    var editor = window.createEditor('[name="content"]');
                });
            </script>
        </div>
    </div>

    {if isset($authorizes)}
    <div class="layui-form-item">
        <label class="layui-form-label">访问授权</label>
        <div class="layui-input-block">
            {foreach $authorizes as $authorize}
            <label class="think-checkbox">
                <!--{if in_array($authorize['id'],$vo['authorize'])}-->
                <input type="checkbox" checked name="authorize[]" value="{$authorize.id}" lay-ignore> {$authorize.title}
                <!--{else}-->
                <input type="checkbox" name="authorize[]" value="{$authorize.id}" lay-ignore> {$authorize.title}
                <!--{/if}-->
            </label>
            {/foreach}
            {if empty($authorizes)}<span class="color-desc" style="line-height:36px">未配置权限</span>{/if}
        </div>
    </div>
    {/if}

    <div class="layui-form-item">
        <label class="layui-form-label">用户描述</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入用户描述" title="请输入用户描述" class="layui-textarea" name="desc">{$vo.desc|default=""}</textarea>
        </div>
    </div>

    <div class="hr-line-dashed"></div>

    <div class="layui-form-item text-center">
        {if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'>{/if}
        <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>
    <script>window.form.render();</script>
</form>

<script>
    function  sheng() {
        var provinceid = $("#provinceid").val();
        $.ajax({
            url: "{:url('index/cityList')}",
            type: 'post',
            dataType: 'json',
            data: {provinceid:provinceid},
            success: function (res) {
                var data = res.data;
                $("#cityid").html('<option value="">全部</option>');
                $("#districtid").html('');
                if (res.code === 200) {
                    for (i=0;i<data.length;i++){
                        var html = '<option value="'+data[i].id+'">'+data[i].area_name+'</option>';
                        $("#cityid").append(html);
                    }
                } else {
                    layer.msg('添加失败', {icon: 2});
                }
            }
        });
        //alert(provinceid);
    }

    function  xian() {
        var cityid = $("#cityid").val();
        $.ajax({
            url: "{:url('index/districtList')}",
            type: 'post',
            dataType: 'json',
            data: {cityid:cityid},
            success: function (res) {
                var data = res.data;
                $("#districtid").html('<option value="">全部</option>');
                if (res.code === 200) {
                    for (i=0;i<data.length;i++){
                        var html = '<option value="'+data[i].id+'">'+data[i].area_name+'</option>';
                        $("#districtid").append(html);
                    }
                } else {
                    layer.msg('添加失败', {icon: 2});
                }
            }
        });
        //alert(provinceid);
    }

</script>

